package com.seu.spring.advance;

import com.seu.spring.service.HelloService;
import com.seu.spring.service.impl.HelloServiceImpl;
import com.seu.spring.advance.aop.AspectJExpressionPointcut;
import org.junit.Test;

import static org.junit.Assert.assertTrue;

/**
 * AspectJExpressionPointcutTest
 *
 * @author liangfeihu
 * @since 2018/12/28 19:23
 */
public class AspectJExpressionPointcutTest {

    @Test
    public void testClassFilter() throws Exception {
        String expression = "execution(* com.seu.spring.*.*(..))";
        AspectJExpressionPointcut aspectJExpressionPointcut = new AspectJExpressionPointcut();
        aspectJExpressionPointcut.setExpression(expression);
        boolean matches = aspectJExpressionPointcut.matchers(HelloService.class);
        assertTrue(matches);
    }

    @Test
    public void testMethodMatcher() throws Exception {
        String expression = "execution(* com.seu.spring.service.*.*.sayHelloWorld(..))";
        AspectJExpressionPointcut aspectJExpressionPointcut = new AspectJExpressionPointcut();
        aspectJExpressionPointcut.setExpression(expression);
        boolean matches = aspectJExpressionPointcut.matchers(
                HelloServiceImpl.class.getDeclaredMethod("sayHelloWorld"), HelloServiceImpl.class);
        assertTrue(matches);
    }

}